package com.jackeysun.util

import android.content.res.Resources

/**
 *   Created by sunxunchao on 2021/10/29.
 */

fun screenWidth(): Int {
    return Resources.getSystem().displayMetrics.widthPixels
}

fun screenHeight(): Int {
    return Resources.getSystem().displayMetrics.heightPixels
}

/**
 * px->dp
 */
fun Int.dp(): Int {
    val scale = Resources.getSystem().displayMetrics.density
    return this.times(scale).plus(0.5f).toInt()
}

/**
 * dp->px
 */
fun Int.px(): Int {
    val scale = Resources.getSystem().displayMetrics.density
    return this.div(scale).plus(0.5f).toInt()
}

/**
 * px->sp
 */
fun Int.sp(): Int {
    val scale = Resources.getSystem().displayMetrics.scaledDensity
    return this.div(scale).plus(0.5f).toInt()
}